<template>
  <div>
    <Head></Head>
  <div class="main">
    <div>
      <div class="content">
        <div class="content-box">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm">
            <el-form-item>
              <div class="quality">
                <div class="quality-title">
                  <img style="width: 18px;height: 18px;" src="../../images/star.png" alt />
                  <span>主体性质</span>
                </div>
                <div class="quality-option">
                  <el-form-item prop="nature">
                    <el-select
                      clearable
                      v-model="ruleForm.nature"
                      class="elinput-left"
                      placeholder="请选择主体性质"
                      prop="nature"
                    >
                      <el-option
                        v-for="item in options"
                        :key="item"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </div>
              </div>
            </el-form-item>

            <el-form-item>
              <div class="quality">
                <div class="quality-title">
                  <img style="width: 18px;height: 18px;" src="../../images/star.png" alt />
                  <span>姓名</span>
                </div>
                <div class="quality-option">
                  <el-form-item prop="name">
                    <el-input
                      @input="optionId=-1"
                      clearable
                      v-model="ruleForm.name"
                      class="elinput-left"
                      placeholder="请输入权属人姓名"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
            </el-form-item>
            <div class="constraint-term">
              <div
                v-for="(item,index) in optionVale"
                :key="index"
                :class="optionId==item.id? 'constraint-term-item action':'constraint-term-item' "
                @click="nameChang(item)"
              >{{ item.name }}</div>
            </div>

            <el-form-item>
              <div class="quality">
                <div class="quality-title">
                  <img style="width: 18px;height: 18px;" src="../../images/star.png" alt />
                  <span>提供证件类型</span>
                </div>
                <div class="quality-option">
                  <el-form-item prop="certificate">
                    <el-select
                      clearable
                      v-model="ruleForm.certificate"
                      class="elinput-left"
                      placeholder="请选择主体性质"
                    >
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </div>
              </div>
            </el-form-item>

            <!-- 上传图片 -->
            <div class="uploading">
              <el-upload action="#" list-type="picture-card" :auto-upload="false">
                <!-- <i slot="default" class="el-icon-plus"></i> -->
                <div class="uploading-bg">
                  <img src="../../images/portrait.png" alt />
                  <p>上传身份证人像面</p>
                </div>
                <div slot="file" slot-scope="{file}">
                  <img class="el-upload-list__item-thumbnail" :src="file.url" alt />
                  <span class="el-upload-list__item-actions">
                    <span
                      class="el-upload-list__item-preview"
                      @click="handlePictureCardPreview(file)"
                    >
                      <i class="el-icon-zoom-in"></i>
                    </span>
                    <!-- 下载到本地 -->
                    <!-- <span
                      v-if="!disabled"
                      class="el-upload-list__item-delete"
                      @click="handleDownload(file)"
                    >
                      <i class="el-icon-download"></i>
                    </span>-->
                    <span
                      v-if="!disabled"
                      class="el-upload-list__item-delete"
                      @click="handleRemove(file)"
                    >
                      <i class="el-icon-delete"></i>
                    </span>
                  </span>
                </div>
              </el-upload>
              <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt />
              </el-dialog>

              <!-- 国徽面 -->
              <el-upload
                action="#"
                list-type="picture-card"
                :auto-upload="false"
                style="margin-left: 10px;"
              >
                <!-- <i slot="default" class="el-icon-plus"></i> -->
                <div class="uploading-bg">
                  <img src="../../images/portrait.png" alt />
                  <p>上传身份证国徽面</p>
                </div>
                <div slot="file" slot-scope="{file}">
                  <img class="el-upload-list__item-thumbnail" :src="file.url" alt />
                  <span class="el-upload-list__item-actions">
                    <span
                      class="el-upload-list__item-preview"
                      @click="handlePictureCardPreview(file)"
                    >
                      <i class="el-icon-zoom-in"></i>
                    </span>
                    <!-- 下载到本地 -->
                    <!-- <span
                      v-if="!disabled"
                      class="el-upload-list__item-delete"
                      @click="handleDownload(file)"
                    >
                      <i class="el-icon-download"></i>
                    </span>-->
                    <span
                      v-if="!disabled"
                      class="el-upload-list__item-delete"
                      @click="handleRemove(file)"
                    >
                      <i class="el-icon-delete"></i>
                    </span>
                  </span>
                </div>
              </el-upload>
              <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt />
              </el-dialog>
            </div>

            <el-form-item>
              <div class="quality">
                <div class="quality-title">
                  <img style="width: 18px;height: 18px;" src="../../images/star.png" alt />
                  <span>证件号码</span>
                </div>
                <div class="quality-option">
                  <el-form-item>
                    <el-input
                      @input="verifyChange"
                      clearable
                      v-model="ruleForm.IdNum"
                      class="elinput-left"
                      placeholder="请输入单位名称"
                    ></el-input>
                    <div class="hint" v-if="verifyShow">
                      <img src="../../images/mistake.png" alt />
                      <span>格式错误,请填写18位身份证号码</span>
                    </div>
                  </el-form-item>
                </div>
              </div>
            </el-form-item>

            <el-form-item>
              <div class="quality">
                <div class="quality-title">
                  <img style="width: 18px;height: 18px;" src="../../images/star.png" alt />
                  <span>联系方式</span>
                </div>
                <div class="quality-option">
                  <el-form-item>
                    <el-input
                      @input="mobileChange"
                      clearable
                      v-model="ruleForm.mobile"
                      class="elinput-left"
                      placeholder="请输入手机号"
                    ></el-input>
                    <div class="hint" v-if="mobileShow">
                      <img src="../../images/mistake.png" alt />
                      <span>手机号格式错误，请检查</span>
                    </div>
                  </el-form-item>
                  <el-form-item>
                    <el-input
                      @input="mailboxChange"
                      clearable
                      v-model="ruleForm.mailbox"
                      class="elinput-left"
                      placeholder="请输入邮箱"
                    ></el-input>
                    <div class="hint" v-if="mailboxShow">
                      <img src="../../images/mistake.png" alt />
                      <span>邮箱格式错误，请检查</span>
                    </div>
                  </el-form-item>
                </div>
              </div>
            </el-form-item>

            <!-- 地区 -->

            <el-form-item>
              <div class="checkbox">
                <div class="checkbox-title">
                  <img style="width: 18px;height: 18px;" src="../../images/star.png" alt />
                  <span>所在地区</span>
                </div>
                <div class="checkbox-option">
                  <el-form-item prop="province">
                    <el-select
                      clearable
                      v-model="ruleForm.province"
                      class="elinput-left"
                      placeholder="请选择省"
                    >
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="cantonal">
                    <el-select
                      clearable
                      v-model="ruleForm.cantonal"
                      class="elinput-left"
                      placeholder="请选择市"
                    >
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="district">
                    <el-select
                      clearable
                      v-model="ruleForm.district"
                      class="elinput-left"
                      placeholder="请选择区"
                    >
                      <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="detailed">
                    <el-input
                      clearable
                      v-model="ruleForm.detailed"
                      class="elinput-left"
                      placeholder="请输入详细地址"
                    ></el-input>
                  </el-form-item>
                </div>
              </div>
            </el-form-item>

            <!-- 提交 -->
            <el-form-item class="submit">
              <el-button type="primary" class="submit-but" @click="submitForm('ruleForm')">提交并下一步</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="main-their">中国数字人知识产权存证保护平台</div>
    </div>
  </div>
  </div>
</template>

<script>
import Head from '../../components/Head'
export default {
  name: "personalView",
  components: {Head},
  data() {
    return {
      ruleForm: {
        nature: "",
        name: "",
        certificate: "",
        IdNum: "",
        mobile: "",
        mailbox: "",
        province: "",
        cantonal: "",
        district: "",
        detailed: ""
      },
      rules: {
        nature: [
          { required: true, message: "请选择主体性质", trigger: "blur" }
        ],
        name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        certificate: [
          { required: true, message: "请选择证件类型", trigger: "blur" }
        ],
        IdNum: [{ required: true, message: "请输入身份证号", trigger: "blur" }],
        mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }],
        mailbox: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
        province: [{ required: true, message: "请选择省", trigger: "blur" }],
        cantonal: [{ required: true, message: "请选择市", trigger: "blur" }],
        district: [{ required: true, message: "请选择区", trigger: "blur" }],
        detailed: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ]
      },
      options: [
        {
          value: "选项1value",
          label: "选项1"
        },
        {
          value: "选项2value",
          label: "选项2"
        },
        {
          value: "选项3value",
          label: "选项3"
        },
        {
          value: "选项4value",
          label: "选项4"
        },
        {
          value: "选项5value",
          label: "选项5"
        }
      ],
      // 上传图片3个
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      // 验证提示
      verifyShow: true,
      mobileShow: true,
      mailboxShow: true,
      optionVale: [
        {
          name: "张晓月",
          id: 0
        },
        {
          name: "李月",
          id: 1
        },
        {
          name: "张月",
          id: 2
        }
      ],
      optionId: -1
    };
  },
  methods: {
    // 身份证号校验
    verifyChange() {
      var reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/;
      if (reg.test(this.ruleForm.IdNum) === true) {
        this.verifyShow = false;
      } else {
        this.verifyShow = true;
      }
    },
    // 手机号校验
    mobileChange() {
      var mobileReg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
      if (mobileReg.test(this.ruleForm.mobile) === true) {
        this.mobileShow = false;
      } else {
        this.mobileShow = true;
      }
    },
    // 邮箱校验
    mailboxChange() {
      var mailboxReg = /^[0-9a-zA-Z]+([.-_]*[0-9a-zA-Z]+)*@([0-9a-zA-Z]+[-_]*[0-9a-zA-Z]+.)+[0-9a-zA-Z]{2,6}$/;
      if (mailboxReg.test(this.ruleForm.mailbox) === true) {
        this.mailboxShow = false;
      } else {
        this.mailboxShow = true;
      }
    },
    // 提交
    submitForm(formName) {
      if (!this.verifyShow && !this.mobileShow && !this.mailboxShow) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            alert("提交成功!");
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      } else {
        return false;
      }
    },
    nameChang(e) {
      this.ruleForm.name = e.name;
      this.optionId = e.id;
      console.log(e);
    }
  }
};
</script>

<style scoped lang="scss">
.main {
  width: 100%;
  min-width: 70vh;
  background-color: #ebf1fb;
  padding-bottom: 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  &-their {
    width: 100%;
    text-align: center;
    font-size: 16px;
    font-weight: 400;
    color: #999999;
    position: absolute;
    bottom: 28px;
  }
}
.content {
  max-width: 1920px;
  min-width: 1440px;
  margin: auto;
  margin-bottom: 145px;
  margin-top: 30px;
  &-box {
    width: 73%;
    min-width: 1022px;
    margin: auto;
    background-color: #fff;
    padding: 70px 0px 66px 80px;
  }
}

.quality {
  display: flex;

  &-title {
    width: 150px;
    text-align: right;
    font-size: 16px;
    font-weight: 500;
    color: #333333;
  }
  &-option {
    margin-left: 20px;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    position: relative;
    margin-bottom: -20px;
  }
}
.constraint-term {
  width: 60%;
  margin-bottom: 10px;
  padding-left: 170px;
  // outline: 2px solid red;
  display: flex;
  flex-wrap: wrap;
  &-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 78px;
    height: 34px;
    border: 1px solid #3a7bd8;
    background: rgba(58, 123, 216, 0.1);
    font-size: 16px;
    font-weight: 400;
    color: #3a7bd8;
    margin: 0 10px 10px 0;
    cursor: pointer;
  }
}
.action {
  color: #fff;
  background-color: #3a7bd8;
}
.hint {
  position: absolute;
  width: 100%;
  height: 20px;
  line-height: 8px;
  display: flex;
  align-items: center;
  color: #ff0000;
  font-size: 14px;
  font-weight: 400;
  margin-left: 20px;
  // outline: 2px solid red;
  > img {
    width: 14px;
    height: 14px;
    margin-right: 5px;
  }
}
.checkbox {
  display: flex;

  &-title {
    width: 150px;
    text-align: right;
    font-size: 16px;
    font-weight: 500;
    color: #333333;
  }
  &-option {
    flex: 1;
    margin-left: 20px;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}
.elinput-left {
  width: 482px !important;
  height: 46px !important;
  margin-right: 20px;
  //  margin-bottom: 20px;
}

.uploading {
  margin-left: 170px;
  margin-bottom: 20px;
  display: flex;
  &-bg {
    width: 214px;
    height: 136px;
    display: flex;
    flex-direction: column;
    align-items: center;

    > img {
      width: 108px;
      height: 59px;
      margin-top: 28px;
      border: 1px dashed #c0ccda;
    }
    > p {
      font-size: 16px;
      font-weight: 400;
      color: #3a7bd8;
      margin-top: 15px;
    }
  }
}

.submit {
  margin-top: 80px;
  display: flex;
  justify-content: center;
  &-but {
    width: 414px;
    height: 66px;
    color: #fff;
    font-size: 20px;
    font-weight: 400;
    background: linear-gradient(135deg, #3b7ad8, #10a3e4);
    outline: none;
  }
}

:deep .el-upload--picture-card {
  width: 214px;
  height: 136px;
  // border: none;
  line-height: 0px;
}
:deep .el-form-item {
  margin-bottom: 20px;
}
</style>
